package usercontroller

import (
	"context"
	"gitee.com/go-mid/booter/bootservice"
	"gitee.com/go-mid/booter/web"
	"gitee.com/go-mid/infra/xlog"
	"gitee.com/go-mid/user/userservice"
)

// 查询
type GetUserAttrConfRequest struct {
	userservice.GetUserAttrConfReq
} //@name 获取用户属性配置请求

func FactoryGetUserAttrConfRequest() web.HandleRequest {
	return new(GetUserAttrConfRequest)
}

//
// @Summary      获取用户属性配置
// @Description  根据id获取用户属性配置详情
// @Tags
// @Param        message	body		GetUserAttrConfRequest	true	"入参"
// @Success      200  {object}  web.ApiReturn{payload=userservice.GetUserAttrConfRes} "响应"
// @Router       /user-attr-conf/get [post]
func (m *GetUserAttrConfRequest) Handle(ctx context.Context, c *bootservice.Context, clientInfo web.XFRMClientInfo, authInfo web.XFRMAuthInfo) (interface{}, error) {
	fun := "UserAttrConfController.GetUserAttrConf -->"
	res, err := userservice.DefaultUserService.GetUserAttrConf(ctx, &m.GetUserAttrConfReq)
	if err != nil {
		xlog.Warnf(ctx, "%s DefaultUserService.GetUserAttrConf err: req: %v  err: %v", fun, m, err)
		return nil, err
	}

	return res, nil
}

// 列表
type ListUserAttrConfRequest struct {
	userservice.ListUserAttrConfReq
} //@name 查询用户属性配置请求

func FactoryListUserAttrConfRequest() web.HandleRequest {
	return new(ListUserAttrConfRequest)
}

//
// @Summary      查询用户属性配置
// @Description  根据条件查询用户属性配置详情
// @Tags
// @Param        message	body		ListUserAttrConfRequest	true	"入参"
// @Success      200  {object}  web.ApiReturn{payload=userservice.ListUserAttrConfRes} "响应"
// @Router       /user-attr-conf/list [post]
func (m *ListUserAttrConfRequest) Handle(ctx context.Context, c *bootservice.Context, clientInfo web.XFRMClientInfo, authInfo web.XFRMAuthInfo) (interface{}, error) {
	fun := "UserAttrConfController.ListUserAttrConf -->"
	res, err := userservice.DefaultUserService.ListUserAttrConf(ctx, &m.ListUserAttrConfReq)
	if err != nil {
		xlog.Warnf(ctx, "%s DefaultUserService.ListUserAttrConf err: req: %v  err: %v", fun, m, err)
		return nil, err
	}

	return res, nil
}

// 添加
type AddUserAttrConfRequest struct {
	userservice.AddUserAttrConfReq
} //@name 添加用户属性配置请求

func FactoryAddUserAttrConfRequest() web.HandleRequest {
	return new(AddUserAttrConfRequest)
}

//
// @Summary      添加用户属性配置
// @Description  添加一条用户属性配置记录
// @Tags
// @Param        message	body		AddUserAttrConfRequest	true	"入参"
// @Success      200  {object}  web.ApiReturn{payload=userservice.AddUserAttrConfRes} "响应"
// @Router       /user-attr-conf/add [post]
func (m *AddUserAttrConfRequest) Handle(ctx context.Context, c *bootservice.Context, clientInfo web.XFRMClientInfo, authInfo web.XFRMAuthInfo) (interface{}, error) {
	fun := "UserAttrConfController.AddUserAttrConf -->"
	res, err := userservice.DefaultUserService.AddUserAttrConf(ctx, &m.AddUserAttrConfReq)
	if err != nil {
		xlog.Warnf(ctx, "%s DefaultUserService.AddUserAttrConf err: req: %v  err: %v", fun, m, err)
		return nil, err
	}

	return res, nil
}

// 修改
type UpdateUserAttrConfRequest struct {
	userservice.UpdateUserAttrConfReq
} //@name 修改用户属性配置请求

func FactoryUpdateUserAttrConfRequest() web.HandleRequest {
	return new(UpdateUserAttrConfRequest)
}

//
// @Summary      修改用户属性配置
// @Description  修改用户属性配置记录
// @Tags
// @Param        message	body		UpdateUserAttrConfRequest	true	"入参"
// @Success      200  {object}  web.ApiReturn{payload=userservice.UpdateUserAttrConfRes} "响应"
// @Router       /user-attr-conf/update [post]
func (m *UpdateUserAttrConfRequest) Handle(ctx context.Context, c *bootservice.Context, clientInfo web.XFRMClientInfo, authInfo web.XFRMAuthInfo) (interface{}, error) {
	fun := "UserAttrConfController.UpdateUserAttrConf -->"
	res, err := userservice.DefaultUserService.UpdateUserAttrConf(ctx, &m.UpdateUserAttrConfReq)
	if err != nil {
		xlog.Warnf(ctx, "%s DefaultUserService.UpdateUserAttrConf err: req: %v  err: %v", fun, m, err)
		return nil, err
	}

	return res, nil
}

// 添加或修改
type UpsertUserAttrConfRequest struct {
	userservice.UpsertUserAttrConfReq
} //@name 添加或修改用户属性配置请求

func FactoryUpsertUserAttrConfRequest() web.HandleRequest {
	return new(UpsertUserAttrConfRequest)
}

//
// @Summary      添加或修改用户属性配置
// @Description  添加或修改用户属性配置记录
// @Tags
// @Param        message	body		UpsertUserAttrConfRequest	true	"入参"
// @Success      200  {object}  web.ApiReturn{payload=userservice.UpsertUserAttrConfRes} "响应"
// @Router       /user-attr-conf/upsert [post]
func (m *UpsertUserAttrConfRequest) Handle(ctx context.Context, c *bootservice.Context, clientInfo web.XFRMClientInfo, authInfo web.XFRMAuthInfo) (interface{}, error) {
	fun := "UserAttrConfController.UpsertUserAttrConf -->"
	res, err := userservice.DefaultUserService.UpsertUserAttrConf(ctx, &m.UpsertUserAttrConfReq)
	if err != nil {
		xlog.Warnf(ctx, "%s DefaultUserService.UpsertUserAttrConf err: req: %v  err: %v", fun, m, err)
		return nil, err
	}

	return res, nil
}
